<template>
    <div>
        <h2>添加房号页面</h2>

        <table class="table table-bordered">
            <tbody>
                <tr>
                    <td>房型</td>
                    <td>
                        <select v-model="queryInfo.TypeId">
                            <option value="">请选择</option>
                            <option :value="item.TypeName" v-for="item in bb.list" :key="item.Id">{{item.TypeName}}</option>
                        </select>
                    </td>
                </tr>

                <tr>
                    <td>房间号码</td>
                    <td>
                       <input type="text" v-model="queryInfo.NumName">
                    </td>
                </tr>

                <tr>
                    <td>房间描述</td>
                    <td>
                       <textarea cols="50" rows="5" v-model="queryInfo.Desc"></textarea>
                    </td>
                </tr>

                <tr>
                    <td>状态</td>
                    <td>
                        <input type="radio" name="state" :value="0" v-model="queryInfo.State">上架
                        <input type="radio" name="state" :value="1" v-model="queryInfo.State">下架
                    </td>
                </tr>

                <tr>
                    <td></td>
                    <td>
                        <input type="button" value="添加" class="btn btn-primary" @click="ok">
                    </td>
                </tr>

            </tbody>
        </table>
    </div>
</template>

<script setup lang="ts">
import { ref, reactive, onMounted } from 'vue'
import axios from 'axios';
import { useRouter, useRoute } from 'vue-router';
const router = useRouter();
const route = useRoute();
import moment from 'moment';

//---------下拉绑定---------
onMounted(()=>{
    getType();
})

let bb:any=reactive({
    list:[]
})
const getType=()=>{
    axios({
        method:'get',
        url:'/api/Week3/ShowWeek3Type',
        params:{
            pageIndex:1,
            pageSize:1000
        }
    })
    .then(res=>{
        console.log(res);
        bb.list=res.data.list;
    })
    .catch(err=>{
        console.log(err);
    })
}

let queryInfo=reactive({
  "TypeId": "",
  "NumName": '',
  "Desc": "",
  "State": '',
})
const ok=()=>{
    //有效性验证
    if(queryInfo.TypeId==""){
        alert('房型必选');
        return;
    }
    if(queryInfo.NumName==""){
        alert('房间号码不能为空');
        return;
    }
    if(queryInfo.Desc==""){
        alert('房间描述不能为空');
        return;
    }
    if(queryInfo.State===""){
        alert('状态必选');
        return;
    }

    //返回网络请求
    axios({
        method:'post',
        url:'/api/Week3/AddNum',
        data:queryInfo
    })
    .then(res=>{
        console.log(res);
        if(res.data==-1){
            alert('房间号码不能重复');
            return;
        }
        if(res.data>0){
            alert('成功');
            router.push('/hNumShow');
        }
        else{
            alert('失败');
        }
    })
    .catch(err=>{
        console.log(err);
    })
}


</script>

<style scoped>

</style>